package cn.jnetty.ioc.definition;
import cn.jnetty.api.JnettyServer;
import cn.jnetty.api.annotation.JEnableSocket;
import cn.jnetty.remoting.http.JnettyHttpServer;
import cn.jnetty.remoting.tcp.JnettyTcpServer;
import cn.jnetty.remoting.udp.JnettyUdpServer;
import cn.jnetty.remoting.websocket.JnettyWebsocketServer;
/**
 * @author 猪哥亮
 * @email 1030681978@qq.com
 * @date 2020/4/3 18:02
 * 描述：
 */
public class JSocketBeanDefinition extends JDefaultBeanDefinition {
    public JSocketBeanDefinition(JEnableSocket component,Class clazz) {
        super(component,clazz);
        init();
    }

    @Override
    protected void init() {
        JEnableSocket.JnettySocketType[] value = ((JEnableSocket)annotation).value();
        for (JEnableSocket.JnettySocketType jnetyType : value) {
            JnettyServer server = null;
            switch (jnetyType) {
                case NONE:
                    break;
                case TCP:
                    server = (JnettyTcpServer) JDefaultBeanDefinitionFactory.getInstance().getBean(JnettyTcpServer.class);
                    break;
                case UDP:
                    server = (JnettyUdpServer) JDefaultBeanDefinitionFactory.getInstance().getBean(JnettyUdpServer.class);
                    break;
                case HTTP:
                    server = (JnettyHttpServer) JDefaultBeanDefinitionFactory.getInstance().getBean(JnettyHttpServer.class);
                    break;
                case WEBSOCKET:
                    server = (JnettyWebsocketServer) JDefaultBeanDefinitionFactory.getInstance().getBean(JnettyWebsocketServer.class);
                    break;
                default:
                    break;
            }
            if (server != null) {
                server.init();
                server.startup();
            }
        }
    }
}
